package com.mcgrady.oop;

import org.junit.Test;

/**
 * @author McGrady
 */
public class InitBlockTest {
    static class Dog {
        public Dog() {
            System.out.println("我是狗类构造器...");
        }

        public Dog(String name) {
            System.out.println("我是狗类构造器..." + name);
        }
    }

    @Test
    public void constructor() {
        new Dog();
        new Dog();
        new Dog("beibei");
        new Dog("baobao");
    }

    static class Dog1 {

        /**
         * 狗类构造器
         */
        public Dog1(String name) {
            this(25);
            System.out.println(1);
        }

        /**
         * 狗类构造器
         */
        public Dog1(int age) {
            System.out.println(2);
        }

        /**
         * 狗类构造器
         */
        public Dog1() {
            this("25");
            System.out.println(3);
        }

        {
            System.out.println("我是动态块01");
        }

        {
            System.out.println("我是动态块02");
        }

        static {
            System.out.println("我是静态块01");
        }

        static {
            System.out.println("我是静态块02");
        }

    }

    @Test
    public void constructor1() {
        new Dog1();
        new Dog1();
    }
}
